package com.fizzkai.p2p.bussness.domain;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fizzkai.p2p.core.domain.BaseAuthDomain;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
// 申请充值对象
public class RechargeOffline extends BaseAuthDomain {
    private PlatformBankInfo bankInfo;//平台账户
    private String tradeCode;//交易号
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date rechargeDate;//交易日期
    private BigDecimal amount;//充值金额
    private String note;//备注信息

    public String getJsonString() throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("id", getId());
        map.put("username", getApplier().getUsername());
        map.put("tradeCode", tradeCode);
        map.put("amount", amount);
        map.put("rechargeDate", new SimpleDateFormat("yyyy-MM-dd").format(rechargeDate));
        return new ObjectMapper().writeValueAsString(map);
    }
}
